<div class="grid">
    <div class="col-12">
        <div class="card">
            <div class="card-w-title">
                <h5 style="font-weight: 900">许可证管理</h5>
            </div>
            <p-toolbar>
                <div
                    class="p-toolbar-group-left flex flex-wrap formgroup-inline"
                ></div>

                <div class="p-toolbar-group-right formgroup-inline">
                    <div class="field">
                        <button
                            pButton
                            type="button"
                            label="新增许可证"
                            icon="pi pi-plus"
                            class="mr-2"
                            (click)="openDialog()"
                        ></button>
                    </div>
                </div>
            </p-toolbar>
        </div>
    </div>
    <div class="col-12">
        <div class="card" style="min-height:625px">
            <p-table
                #dt1
                [value]="data"
                dataKey="wellCode"
                [rowHover]="true"
                [rows]="10"
                [paginator]="true"
                [rowsPerPageOptions]="[10, 25, 50]"
                scrollDirection="both"
                [scrollable]="true"
                styleClass="p-datatable-striped"
                responsiveLayout="scroll"
            >
                <ng-template pTemplate="header">
                    <tr>
                        <th width="120" pFrozenColumn>
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                许可证名称
                            </div>
                        </th>
                        <th width="150">
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                许可证状态
                            </div>
                        </th>
                        <th width="200">
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                一年许可水量(万m³)
                            </div>
                        </th>
                        <th width="150">
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                所属用户
                            </div>
                        </th>
                        <th width="300">
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                管理部门
                            </div>
                        </th>
                        <th width="150">
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                起始时间
                            </div>
                        </th>
                        <th width="350" pFrozenColumn alignFrozen="right">
                            <div
                                class="flex justify-content-between align-items-center"
                            >
                                操作
                            </div>
                        </th>
                    </tr>
                </ng-template>
                <ng-template pTemplate="body" let-item>
                    <tr>
                        <td width="120" pFrozenColumn>
                            {{ item.license }}
                        </td>
                        <td width="150">
                            {{ ['','可用','不可用'][item.available] }}
                        </td>
                        <td width="200">
                            {{ item.licenseVolume }}
                        </td>
                        <td width="150">
                            {{ item.applicantName }}
                        </td>
                        <td width="300">
                            {{ item.departmentName }}
                        </td>
                        <td width="150">
                            {{ item.startTime }}
                        </td>
                        <td
                            width="350"
                            style="text-align: center"
                            pFrozenColumn
                            alignFrozen="right"
                        >
                            <button
                                pButton
                                pRipple
                                type="button"
                                label="修改许可"
                                class="p-button-secondary"
                                style="margin-left: 20px"
                                (click)="openDialog2(item)"
                            ></button>
                            <button
                                pButton
                                pRipple
                                type="button"
                                label="删除"
                                class="p-button-danger"
                                style="margin-left: 20px"
                                (click)="deleteLicense(item)"
                            ></button>
                        </td>
                    </tr>
                </ng-template>
                <ng-template pTemplate="emptymessage">
                    <tr>
                        <td colspan="7">没有找到许可证信息</td>
                    </tr>
                </ng-template>
                <ng-template pTemplate="loadingbody">
                    <tr>
                        <td colspan="7">正在加载许可证信息，请稍等</td>
                    </tr>
                </ng-template>
            </p-table>
        </div>
    </div>
</div>
<p-dialog
    [header]="editTag ? '修改许可证' : '新增许可证'"
    [(visible)]="display"
    [modal]="true"
    [style]="{ width: '600px', height: '600px' }"
    [draggable]="false"
    [resizable]="false"
>
    <div class="field grid">
        <label for="email" class="col-fixed w-9rem">用水户</label>
        <div class="col">
            <!--input
                type="text"
                [(ngModel)]="addForm.applicantId"
                pInputText
                label="email"
                class="ng-dirty ng-invalid"
            /-->
            <p-dropdown
                [options]="applicant"
                [(ngModel)]="addForm.applicantId"
                optionLabel="applicantName"
                optionValue="applicantId"
                placeholder="选择用水户"
            ></p-dropdown>
        </div>
    </div>
    <div class="field grid">
        <label for="email" class="col-fixed w-9rem">起始时间</label>
        <div class="col">
            <!--input
                type="text"
                [(ngModel)]="addForm.startTime"
                pInputText
                label="email"
                class="ng-dirty ng-invalid mr-2"
            /-->
            <p-calendar
                inputId="basic"
                [(ngModel)]="addForm.startTime"
            ></p-calendar>
        </div>
    </div>
    <div class="field grid">
        <label for="email" class="col-fixed w-9rem">许可证状态</label>
        <div class="col">
            <!--input
                type="text"
                [(ngModel)]="addForm.available"
                pInputText
                label="email"
                class="ng-dirty ng-invalid"
            /-->
            <p-dropdown
                [options]="licenseStates"
                [(ngModel)]="addForm.available"
                optionLabel="label"
                optionValue="value"
                placeholder="选择许可证状态"
            ></p-dropdown>
        </div>
    </div>
    <div class="field grid">
        <label for="email" class="col-fixed w-9rem">管理部门</label>
        <div class="col">
            <!--input
                type="text"
                [(ngModel)]="addForm.departmentId"
                pInputText
                label="email"
                class="ng-dirty ng-invalid"
            /-->
            <p-dropdown
                [options]="departments"
                [(ngModel)]="addForm.departmentId"
                optionLabel="label"
                optionValue="value"
                placeholder="选择管理部门"
            ></p-dropdown>
        </div>
    </div>
    <div class="field grid">
        <label for="email" class="col-fixed w-9rem">许可证名称 </label>
        <div class="col">
            <input
                type="text"
                [(ngModel)]="addForm.license"
                pInputText
                label="email"
                class="ng-dirty ng-invalid"
            />
        </div>
    </div>
    <div class="field grid">
        <label for="email" class="col-fixed w-9rem">许可水量</label>
        <div class="col">
            <input
                type="text"
                [(ngModel)]="addForm.licenseVolume"
                pInputText
                label="email"
                class="ng-dirty ng-invalid"
            />
        </div>
    </div>
    <ng-template pTemplate="footer">
        <p-button
            (click)="submit()"
            label="保存"
            styleClass="p-button-text"
        ></p-button>
        <p-button
            (click)="display = false"
            label="取消"
            styleClass="p-button-text"
        ></p-button>
    </ng-template>
</p-dialog>
<p-confirmDialog [style]="{ width: '450px' }"></p-confirmDialog>
<p-toast></p-toast>
